package com.yanghang.controller;

import com.github.pagehelper.PageInfo;
import com.yanghang.entity.Car;
import com.yanghang.service.CarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController
public class CarController {
    private int pageSize=4;
    @Autowired
    private CarService cs;

    @GetMapping("/cars/{tid}/{pageNum}")
    public PageInfo<Car> selectByPage(@PathVariable("tid") @RequestParam(defaultValue = "-1") int tid,@PathVariable("pageNum")@RequestParam(defaultValue = "1") int pageNum){
        return cs.selectCarByPage(tid,pageNum,pageSize);
    }
    @DeleteMapping("/cars/{id}")
    public void deleteCar(@PathVariable("id") int id){
        cs.deleteCar(id);
    }
    @PostMapping("/cars")
    public void insertCar(@RequestBody Car car){
        cs.insertCar(car);
    }

    @PutMapping("/cars")
    public void updateCar(@RequestBody Car car){
        cs.updateCar(car);
    }
}
